home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / button.lib < prev    next >
Text File  |  1995-06-04  |  3KB  |  80 lines

  1. // Button.lib - Work with button using SCREEN.LIB library
  2. // ver.1
  3. //
  4. //*** CreateButton() - initialize button structure
  5. // SYNTAX: struct CreateButton(string Text,int Row,int Col,int Height,int Width,
  6. //                             int ForeColor,int BackColor,
  7. //                             bool 3D,bool Lines)
  8. // WHERE: Text: String to print in middle of button
  9. //        Row,Col: Starting row and column of button
  10. //        Height,Width: button height and width, including lines but not shadow
  11. //        ForeColor,BackColor: Foreground and background color of button
  12. //        3D: If true then push button (shadow), else inverse button
  13. //        Lines: 0 for no line, else SINGLE_LINE or DOUBLE_LINE
  14. // NOTE: This function may move cursor, and looks at current screen color
  15. //       to get background color if 3D. Does not change color
  16. //
  17. //*** PushButton() - Push selected button
  18. // SYNTAX: void PushButton(struct button,bool SoundEffects)
  19. // WHERE: button: struct returned by CreateButton
  20. //        SoundEffects: if True then make a click noise, else not
  21. // NOTE: Does not change default color
  22. //
  23.  
  24. #include <Screen.lib>
  25. #include <sound.lib>
  26.  
  27. CreateButton(pText,pRow,pCol,pHeight,pWidth,pFore,pBack,p3D,pLines)
  28. {
  29.    // initialize button structure
  30.    strcpy(lButt.Text,pText);
  31.    lButt.x0 = pCol; lButt.y0 = pRow;
  32.    lButt.x1 = pCol + pWidth - 1; lButt.y1 = pRow + pHeight - 1;
  33.    lButt.Fore = pFore; lButt.Back = pBack;
  34.    lButt.shade = p3D ? SHADOW : 0; lButt.lines = pLines;
  35.    lButt.TextRow = pRow + pHeight / 2;
  36.    lButt.TextCol = pCol + (pWidth - strlen(pText))/2
  37.    // get background if 3D
  38.    if ( p3D ) {
  39.       ReadCharacter(pRow,pCol,lButt.attribute);
  40.    }
  41.    // draw the initial button
  42.    lSaveFore = slForeColor; lSaveBack = slBackColor;
  43.    TextBox(pRow,pCol,lButt.y1,lButt.x1,pFore,pBack,pLines | lButt.shade);
  44.    ScrWrite(pText,lButt.TextRow,lButt.TextCol);
  45.    slForeColor = lSaveFore; slBackColor = lSaveBack;
  46.    // return the structure to use later
  47.    return lButt;
  48. }
  49.  
  50. PushButton(pButt,pSound)
  51. {
  52.    lSaveFore = slForeColor; lSaveBack = slBackColor;
  53.    if ( pButt.shade ) {
  54.       SetAttribute(pButt.attribute);
  55.       Scroll(0,pButt.y0,pButt.x0,pButt.y1+1,pButt.x1+2);
  56.       TextBox(pButt.y0+1,pButt.x0+2,pButt.y1+1,pButt.x1+2,
  57.               pButt.Fore,pButt.Back,pButt.lines);
  58.       ScrWrite(pButt.Text,pButt.TextRow+1,pButt.TextCol+2);
  59.       if ( pSound ) sound(250,0);
  60.       suspend(300);
  61.       SetAttribute(pButt.attribute);
  62.       Scroll(0,pButt.y0,pButt.x0,pButt.y1+1,pButt.x1+2);
  63.       TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
  64.               pButt.Fore,pButt.Back,pButt.lines|SHADOW);
  65.       ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
  66.       if ( pSound ) sound(300,0);
  67.    } else {
  68.       TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
  69.               pButt.Back,pButt.Fore & 0x7,pButt.lines);
  70.       ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
  71.       if ( pSound ) sound(250,0);
  72.       suspend(300);
  73.       TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
  74.               pButt.Fore,pButt.Back,pButt.lines);
  75.       ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
  76.       if ( pSound ) sound(300,0);
  77.    }
  78.    slForeColor = lSaveFore; slBackColor = lSaveBack;
  79. }
  80.